<template>
  <header class="header-nav">
    <!-- 左侧Logo和标题部分 -->
    <div class="header-left">
      <a href="#" class="logo-link">
        <svg class="logo" viewBox="0 0 32 32" fill="currentColor">
          <path d="M16 0C7.164 0 0 7.164 0 16s7.164 16 16 16 16-7.164 16-16S24.836 0 16 0zm0 28c-6.627 0-12-5.373-12-12s5.373-12 12-12 12 5.373 12 12-5.373 12-12 12z"/>
          <path d="M13 10v6l5-3z"/>
        </svg>
        <span class="title">Gitee</span>
      </a>
    </div>

    <!-- 中间导航链接部分 -->
    <nav class="header-center">
      <a href="#" class="nav-link active">首页</a>
      <a href="#" class="nav-link">探索</a>
      <a href="#" class="nav-link">动态</a>
      <a href="#" class="nav-link">项目</a>
      <a href="#" class="nav-link">团队</a>
    </nav>

    <!-- 右侧用户菜单部分 -->
    <div class="header-right">
      <div class="search-box">
        <input type="text" placeholder="搜索" class="search-input">
      </div>
      <div class="notification">
        <svg viewBox="0 0 16 16" fill="currentColor">
          <path d="M8 16a2 2 0 001.985-1.75c.015-.137-.097-.25-.235-.25h-3.5c-.138 0-.25.113-.235.25A2 2 0 008 16zm6-8a6 6 0 11-12 0 6 6 0 0112 0zM8 10a2 2 0 100-4 2 2 0 000 4z"/>
        </svg>
      </div>
      <div class="user-menu">
        <div class="user-avatar" @click="toggleUserMenu">
          <svg viewBox="0 0 16 16" fill="currentColor">
            <path d="M8 8a3 3 0 100-6 3 3 0 000 6zm2-3a2 2 0 11-4 0 2 2 0 014 0zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4z"/>
          </svg>
        </div>
        <div v-if="showUserMenu" class="dropdown-menu">
          <a href="#" class="dropdown-item">个人主页</a>
          <a href="#" class="dropdown-item">项目管理</a>
          <a href="#" class="dropdown-item">设置</a>
          <div class="dropdown-divider"></div>
          <a href="#" class="dropdown-item">退出登录</a>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup>
import { ref } from 'vue';

// 用户菜单显示状态
const showUserMenu = ref(false);

// 切换用户菜单显示/隐藏
const toggleUserMenu = () => {
  showUserMenu.value = !showUserMenu.value;
};

// 点击页面其他地方关闭用户菜单
const handleClickOutside = (event) => {
  const userMenu = document.querySelector('.user-menu');
  if (userMenu && !userMenu.contains(event.target)) {
    showUserMenu.value = false;
  }
};

// 生命周期钩子：挂载时添加点击事件监听
import { onMounted, onUnmounted } from 'vue';

onMounted(() => {
  document.addEventListener('click', handleClickOutside);
});

onUnmounted(() => {
  document.removeEventListener('click', handleClickOutside);
});
</script>

<style scoped>
/* 头部导航栏基础样式 */
.header-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  background-color: #ffffff;
  border-bottom: 1px solid #e6e6e6;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 1000;
}

/* 左侧Logo和标题 */
.header-left {
  display: flex;
  align-items: center;
}

.logo-link {
  display: flex;
  align-items: center;
  color: #171717;
  text-decoration: none;
}

.logo {
  width: 32px;
  height: 32px;
  margin-right: 8px;
  color: #ff85c0;
}

.title {
  font-size: 18px;
  font-weight: 600;
  color: #171717;
}

/* 中间导航链接 */
.header-center {
  display: flex;
  align-items: center;
}

.nav-link {
  padding: 0 16px;
  height: 50px;
  line-height: 50px;
  color: #555;
  text-decoration: none;
  font-size: 14px;
  transition: all 0.2s;
  position: relative;
}

.nav-link:hover {
  color: #ff85c0;
  background-color: #f8f8f8;
}

.nav-link.active {
  color: #ff85c0;
  background-color: #f8f8f8;
}

.nav-link.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background-color: #ff85c0;
}

/* 右侧用户菜单区域 */
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* 搜索框 */
.search-box {
  position: relative;
}

.search-input {
  width: 200px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: #ff85c0;
}

/* 通知图标 */
.notification {
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: color 0.2s;
}

.notification:hover {
  color: #ff85c0;
}

.notification svg {
  width: 18px;
  height: 18px;
}

/* 用户菜单 */
.user-menu {
  position: relative;
}

.user-avatar {
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background-color 0.2s;
}

.user-avatar:hover {
  background-color: #e6e6e6;
}

.user-avatar svg {
  width: 18px;
  height: 18px;
}

/* 下拉菜单 */
.dropdown-menu {
  position: absolute;
  top: 40px;
  right: 0;
  min-width: 160px;
  background-color: #fff;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1001;
}

.dropdown-item {
  display: block;
  padding: 8px 16px;
  color: #555;
  text-decoration: none;
  font-size: 14px;
  transition: background-color 0.2s;
}

.dropdown-item:hover {
  background-color: #f8f8f8;
  color: #ff85c0;
}

.dropdown-divider {
  height: 1px;
  margin: 4px 0;
  background-color: #e6e6e6;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .header-nav {
    padding: 0 12px;
  }
  
  .title {
    display: none;
  }
  
  .header-center {
    display: none;
  }
  
  .search-input {
    width: 120px;
  }
}
</style>